package com.onlyxiahui.framework.json.validator.impl;

import com.alibaba.fastjson.JSONObject;
import com.onlyxiahui.framework.json.validator.Validator;
import com.onlyxiahui.framework.json.validator.ValidatorError;
import com.onlyxiahui.framework.json.validator.ValidatorResult;

/**
 * 
 * Date 2018-12-26 15:47:21<br>
 * Description
 * 
 * @author XiaHui<br>
 * @since 1.0.0
 */
public class JsonNotNullValidator implements Validator<JSONObject, Object> {

	@Override
	public String getKey() {
		return "notNull";
	}

	@Override
	public ValidatorResult valid(JSONObject data, Object attribute, Object judge, String code, String message) {
		ValidatorResult vr = null;
		boolean mark = null != attribute;

		if (!mark) {
			vr = new ValidatorResult();
			vr.setErrorCode(code == null ? this.getCode() : code);
			vr.setMessage(message == null ? this.getMessage() : message);
		}
		return vr;
	}

	public String getMessage() {
		return "不能为空！";
	}

	public String getCode() {
		return ValidatorError.is_null;
	}
}
